<?php
declare (strict_types = 1);

namespace app\common\system\model;

use app\common\config\logic\DictionaryLogic;
use app\common\config\model\ConfigStore;
use think\Model;
use think\model\concern\SoftDelete;

class User extends Model
{
    protected $table = "tk_system_user";
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    public function department()
    {
        return $this->hasMany(UserDepartment::class, 'user_id', 'id');
    }

    public function role()
    {
        return $this->hasMany(UserRole::class, 'user_id', 'id');
    }

    public function getStoreAttr($value, $data) {
        $dictionaryLogic = new DictionaryLogic();
        $store = $dictionaryLogic->getItem($data['store_id'], ConfigStore::class, ['id', 'title']);

        if (empty($store)) {
            $store = [
                'id' => '',
                'title' => ''
            ];
        }

        return $store;
    }
}
